/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogPanel.java
 *
 * Created on Nov 18, 2009, 8:08:53 PM
 */

package gpa4;

import java.awt.event.KeyEvent;

/**
 *
 * @author Trixie
 */
/*
 * DialogPanel is the config panel for configuring the keys that used to play
 * the game
 *
 */
public class DialogPanel extends javax.swing.JPanel {

    /** Creates new form DialogPanel */
    public DialogPanel() {
        initComponents();
        isLeftPressed = false;
        isRightPressed = false;
        isDownPressed = false;
        isRotatePressed = false;
        keyLeft = KeyEvent.VK_A;
        keyRight = KeyEvent.VK_D;
        keyDown = KeyEvent.VK_S;
        keyRotate = KeyEvent.VK_W;
        keyLeft1 = KeyEvent.VK_LEFT;;
        keyRight1 = KeyEvent.VK_RIGHT;;
        keyDown1 = KeyEvent.VK_DOWN;
        keyRotate1 = KeyEvent.VK_UP;
        jLabelLeft.setText("KEY " + keyLeft);
        jLabelRight.setText("KEY " + keyRight);
        jLabelDown.setText("KEY " + keyDown);
        jLabelRotate.setText("KEY " + keyRotate);
        jLabelLeft1.setText("KEY " + keyLeft1);
        jLabelRight1.setText("KEY " + keyRight1);
        jLabelDown1.setText("KEY " + keyDown1);
        jLabelRotate1.setText("KEY " + keyRotate1);
    }

    public int getKeyLeft() {return keyLeft;}
    public int getKeyRight() {return keyRight;}
    public int getKeyDown() {return keyDown;}
    public int getKeyRotate() {return keyRotate;}
    public int getKeyLeft1() {return keyLeft1;}
    public int getKeyRight1() {return keyRight1;}
    public int getKeyDown1() {return keyDown1;}
    public int getKeyRotate1() {return keyRotate1;}
    public void dispatchKeyPress(java.awt.event.KeyEvent evt) {
        dialogKeyPressed(evt);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToggleLeft = new javax.swing.JToggleButton();
        jLabelLeft = new javax.swing.JLabel();
        jToggleRight = new javax.swing.JToggleButton();
        jToggleDown = new javax.swing.JToggleButton();
        jToggleRotate = new javax.swing.JToggleButton();
        jLabelRight = new javax.swing.JLabel();
        jLabelDown = new javax.swing.JLabel();
        jLabelRotate = new javax.swing.JLabel();
        jLabelConfig = new javax.swing.JLabel();
        jLabelRotate1 = new javax.swing.JLabel();
        jToggleRotate1 = new javax.swing.JToggleButton();
        jToggleRight1 = new javax.swing.JToggleButton();
        jToggleDown1 = new javax.swing.JToggleButton();
        jLabelLeft1 = new javax.swing.JLabel();
        jLabelDown1 = new javax.swing.JLabel();
        jToggleLeft1 = new javax.swing.JToggleButton();
        jLabelRight1 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dialogKeyPressed(evt);
            }
        });

        jToggleLeft.setText("Left");
        jToggleLeft.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                leftToggled(evt);
            }
        });

        jLabelLeft.setText("Left");

        jToggleRight.setText("Right");
        jToggleRight.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                rightToggled(evt);
            }
        });

        jToggleDown.setText("Down");
        jToggleDown.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                downToggled(evt);
            }
        });

        jToggleRotate.setText("Rotate");
        jToggleRotate.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                rotateToggled(evt);
            }
        });

        jLabelRight.setText("Right");

        jLabelDown.setText("Down");

        jLabelRotate.setText("Rotate");

        jLabelConfig.setText("Toggle and press key to configure... NOTE: Cannot change during game");

        jLabelRotate1.setText("Rotate");

        jToggleRotate1.setText("Rotate");
        jToggleRotate1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jToggleRotate1rotateToggled(evt);
            }
        });

        jToggleRight1.setText("Right");
        jToggleRight1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jToggleRight1rightToggled(evt);
            }
        });

        jToggleDown1.setText("Down");
        jToggleDown1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jToggleDown1downToggled(evt);
            }
        });

        jLabelLeft1.setText("Left");

        jLabelDown1.setText("Down");

        jToggleLeft1.setText("Left");
        jToggleLeft1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jToggleLeft1leftToggled(evt);
            }
        });

        jLabelRight1.setText("Right");

        jLabel1.setText("Player 1");

        jLabel2.setText("Player 2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jToggleLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToggleRotate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToggleRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToggleDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelDown)
                    .addComponent(jLabelRotate)
                    .addComponent(jLabelRight)
                    .addComponent(jLabelLeft))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jToggleLeft1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToggleRotate1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToggleRight1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToggleDown1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelDown1)
                    .addComponent(jLabelRotate1)
                    .addComponent(jLabelRight1)
                    .addComponent(jLabelLeft1))
                .addGap(24, 24, 24))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelConfig)
                .addContainerGap(20, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 158, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(114, 114, 114))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabelConfig)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelLeft)
                            .addComponent(jToggleLeft))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToggleRight)
                            .addComponent(jLabelRight))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToggleDown)
                            .addComponent(jLabelDown))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToggleRotate)
                            .addComponent(jLabelRotate)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelLeft1)
                            .addComponent(jToggleLeft1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToggleRight1)
                            .addComponent(jLabelRight1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToggleDown1)
                            .addComponent(jLabelDown1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToggleRotate1)
                            .addComponent(jLabelRotate1))))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void dialogKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dialogKeyPressed
        int keyCode = evt.getKeyCode();
        //System.out.println(keyCode);

        if (isLeftPressed) {
            keyLeft = keyCode;
            jLabelLeft.setText("KEY " + keyLeft);
            jToggleLeft.setSelected(false);
        }else if (isRightPressed) {
            keyRight = keyCode;
            jLabelRight.setText("KEY " + keyRight);
            jToggleRight.setSelected(false);
        }else if (isDownPressed) {
            keyDown = keyCode;
            jLabelDown.setText("KEY " + keyDown);
            jToggleDown.setSelected(false);
        }else if (isRotatePressed) {
            keyRotate = keyCode;
            jLabelRotate.setText("KEY " + keyRotate);
            jToggleRotate.setSelected(false);
        }
        if (isLeftPressed1) {
            keyLeft1 = keyCode;
            jLabelLeft1.setText("KEY " + keyLeft1);
            jToggleLeft1.setSelected(false);
        }else if (isRightPressed1) {
            keyRight1 = keyCode;
            jLabelRight1.setText("KEY " + keyRight1);
            jToggleRight1.setSelected(false);
        }else if (isDownPressed1) {
            keyDown1 = keyCode;
            jLabelDown1.setText("KEY " + keyDown1);
            jToggleDown1.setSelected(false);
        }else if (isRotatePressed1) {
            keyRotate1 = keyCode;
            jLabelRotate1.setText("KEY " + keyRotate1);
            jToggleRotate1.setSelected(false);
        }
    }//GEN-LAST:event_dialogKeyPressed

    private void leftToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_leftToggled
        if (isLeftPressed) {
            isLeftPressed = false;
        } else {
            isLeftPressed = true;
            if (isRightPressed) {
            jToggleRight.setSelected(false);
            }
            if (isDownPressed) {
            jToggleDown.setSelected(false);
            }
            if (isRotatePressed) {
            jToggleRotate.setSelected(false);
            }
        }
    }//GEN-LAST:event_leftToggled

    private void rightToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_rightToggled
        if (isRightPressed) {
            isRightPressed = false;
        } else {
            isRightPressed = true;
            if (isLeftPressed) {
            jToggleLeft.setSelected(false);
            }
            if (isDownPressed) {
            jToggleDown.setSelected(false);
            }
            if (isRotatePressed) {
            jToggleRotate.setSelected(false);
            }
        }
    }//GEN-LAST:event_rightToggled

    private void downToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_downToggled
        if (isDownPressed) {
            isDownPressed = false;
        } else {
            isDownPressed = true;
            if (isRightPressed) {
            jToggleRight.setSelected(false);
            }
            if (isLeftPressed) {
            jToggleLeft.setSelected(false);
            }
            if (isRotatePressed) {
            jToggleRotate.setSelected(false);
            }
        }
    }//GEN-LAST:event_downToggled

    private void rotateToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_rotateToggled
        if (isRotatePressed) {
            isRotatePressed = false;
        } else {
            isRotatePressed = true;
            if (isRightPressed) {
            jToggleRight.setSelected(false);
            }
            if (isDownPressed) {
            jToggleDown.setSelected(false);
            }
            if (isLeftPressed) {
            jToggleLeft.setSelected(false);
            }
        }
    }//GEN-LAST:event_rotateToggled

    private void jToggleRotate1rotateToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jToggleRotate1rotateToggled
        //System.out.println("rotate1toggle");
        if (isRotatePressed1) {
            isRotatePressed1 = false;
        } else {
            isRotatePressed1 = true;
            if (isRightPressed1) {
            jToggleRight1.setSelected(false);
            }
            if (isDownPressed1) {
            jToggleDown1.setSelected(false);
            }
            if (isLeftPressed1) {
            jToggleLeft1.setSelected(false);
            }
        }
    }//GEN-LAST:event_jToggleRotate1rotateToggled

    private void jToggleRight1rightToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jToggleRight1rightToggled
        if (isRightPressed1) {
            isRightPressed1 = false;
        } else {
            isRightPressed1 = true;
            if (isLeftPressed1) {
            jToggleLeft1.setSelected(false);
            }
            if (isDownPressed1) {
            jToggleDown1.setSelected(false);
            }
            if (isRotatePressed1) {
            jToggleRotate1.setSelected(false);
            }
        }
    }//GEN-LAST:event_jToggleRight1rightToggled

    private void jToggleDown1downToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jToggleDown1downToggled
        if (isDownPressed1) {
            isDownPressed1 = false;
        } else {
            isDownPressed1 = true;
            if (isRightPressed1) {
            jToggleRight1.setSelected(false);
            }
            if (isLeftPressed1) {
            jToggleLeft1.setSelected(false);
            }
            if (isRotatePressed1) {
            jToggleRotate1.setSelected(false);
            }
        }
    }//GEN-LAST:event_jToggleDown1downToggled

    private void jToggleLeft1leftToggled(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jToggleLeft1leftToggled
        if (isLeftPressed1) {
            isLeftPressed1 = false;
        } else {
            isLeftPressed1 = true;
            if (isRightPressed1) {
            jToggleRight1.setSelected(false);
            }
            if (isDownPressed1) {
            jToggleDown1.setSelected(false);
            }
            if (isRotatePressed1) {
            jToggleRotate1.setSelected(false);
            }
        }
    }//GEN-LAST:event_jToggleLeft1leftToggled

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelConfig;
    private javax.swing.JLabel jLabelDown;
    private javax.swing.JLabel jLabelDown1;
    private javax.swing.JLabel jLabelLeft;
    private javax.swing.JLabel jLabelLeft1;
    private javax.swing.JLabel jLabelRight;
    private javax.swing.JLabel jLabelRight1;
    private javax.swing.JLabel jLabelRotate;
    private javax.swing.JLabel jLabelRotate1;
    private javax.swing.JToggleButton jToggleDown;
    private javax.swing.JToggleButton jToggleDown1;
    private javax.swing.JToggleButton jToggleLeft;
    private javax.swing.JToggleButton jToggleLeft1;
    private javax.swing.JToggleButton jToggleRight;
    private javax.swing.JToggleButton jToggleRight1;
    private javax.swing.JToggleButton jToggleRotate;
    private javax.swing.JToggleButton jToggleRotate1;
    // End of variables declaration//GEN-END:variables
    private boolean isLeftPressed;
    private boolean isRightPressed;
    private boolean isDownPressed;
    private boolean isRotatePressed;
    private boolean isLeftPressed1;
    private boolean isRightPressed1;
    private boolean isDownPressed1;
    private boolean isRotatePressed1;
    private int keyLeft;
    private int keyRight;
    private int keyDown;
    private int keyRotate;
    private int keyLeft1;
    private int keyRight1;
    private int keyDown1;
    private int keyRotate1;
}
